package com.qf.eduadmin.controller;


import com.qf.eduadmin.pojo.vo.QfCourse;
import com.qf.eduadmin.pojo.resp.ResponseData;
import com.qf.eduadmin.service.CourseService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mr.Liu
 * @date 2021/12/23 20:05
 */
@RequestMapping("/course")
@RestController
public class CourseController {
    @Autowired
    private CourseService courseService;
    @RequestMapping("/findAllCourse")
    @ApiOperation(value = "查询所有课程")
    @ApiImplicitParams(value = {@ApiImplicitParam(paramType = "query",name = "page",value = "当前页",required = true,dataType = "int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value = "每页显示的条数",required = true,dataType = "int")})
    @RequiresAuthentication
    @RequiresPermissions(value = {"/course/findAllCourse"})
    public ResponseData findAll(@RequestParam("page")Integer page,@RequestParam("limit")Integer limit){
        ResponseData responseData = courseService.findAll(page,limit);
        //System.out.println(responseData);
        return responseData;
    }

    @RequestMapping(value = "/addCourse",method = RequestMethod.POST)
    @RequiresAuthentication
    @RequiresPermissions(value = {"/course/addCourse"})
    public ResponseData insertCourse(@RequestBody QfCourse qfCourse){
        ResponseData responseData = courseService.insertCourse(qfCourse);
        return responseData;
    }

    @RequestMapping("/findById")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/course/findById"})
    public ResponseData findById(@RequestParam("id")Integer id){
        //System.out.println(id);
        ResponseData responseData = courseService.findById(id);
        return responseData;
    }

    @RequestMapping("/updateCourse")
    @RequiresAuthentication
    @RequiresPermissions(value = {"/course/updateCourse"})
    public ResponseData updateCourse(@RequestBody QfCourse qfCourse){
        //System.out.println(qfCourse);
        ResponseData responseData = courseService.updateCourse(qfCourse);
        return responseData;
    }

}
